<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>密码修改</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description"
          content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.">
    <link rel="stylesheet" th:href="@{/wxui/lib/weui.min.css}">
    <link rel="stylesheet" th:href="@{/wxui/css/jquery-weui.css}">
    <link rel="stylesheet" th:href="@{/wxui/css/style.css}">
</head>
<body ontouchstart>
<!--主体-->
<header class="wy-header">
    <div class="wy-header-icon-back"><span></span></div>
    <div class="wy-header-title">密码修改</div>
</header>
<div class="weui-content">
    <form id="editPwdForm">
        <div class="weui-cells cardlist">

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label wy-lab">原密码</label></div>
                <div class="weui-cell__bd"><input class="weui-input" id="oldPwd" name="oldPwd" type="password"
                                                  placeholder="请输入旧密码"></div>
                <div id="pwdMsg" hidden="hidden"></div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label wy-lab">新密码</label></div>
                <div class="weui-cell__bd"><input class="weui-input" id="loginpwd" name="loginpwd" type="password"
                                                  placeholder="请输入新密码"></div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label wy-lab">确认密码</label></div>
                <div class="weui-cell__bd"><input class="weui-input" id="loginpwd2" name="loginpwd2" type="password"
                                                  placeholder="请确认新密码"></div>
            </div>
        </div>
        <div class="mg10-0"><a id="editPwdBtn" href="javascript:;" class="weui-btn weui-btn_primary"
                               style="background-color: #EA869A;">确认修改</a></div>
    </form>
</div>

<script th:src="@{/wxui/lib/jquery-2.1.4.js}"></script>
<script th:src="@{/wxui/lib/fastclick.js}"></script>
<script type="text/javascript" th:src="@{/wxui/js/jquery.Spinner.js}"></script>
<script th:src="@{/wxui/js/jquery-weui.js}"></script>
<script>
    $(function () {
        $(".wy-header-icon-back").click(function () {
            window.history.back();
        });
    });

    $("#editPwdBtn").click(function () {
        if ($("#oldPwd").val() == "") {
            $.toast("原密码不能为空", "text");
            return false;
        }
        if ($("#loginpwd").val() == "") {
            $.toast("新密码不能为空", "text");
            return false;
        }
        if ($("#loginpwd2").val() == "") {
            $.toast("请确认密码", "text");
            return false;
        }
        if ($("#loginpwd").val() != $("#loginpwd2").val()) {
            $.toast("两次密码输入不一致", "text");
            return false;
        }
        $.ajax({
            type: "post",
            url: "/user/frontstage/editUserPwd",
            dataType: 'json',
            data: {
                "oldPwd": $("#oldPwd").val(),
                "newPwd": $("#loginpwd").val()
            },
            success: function (data) {
                if (data.code == 200) {
                    $.toast(data.msg);
                    setTimeout('location.href = "/frontstage/login"', 1000);
                }
                if (data.code == 500) {
                    $.toast(data.msg, "text");
                }
            }
        });

    })


    $("#oldPwd").blur(function () {
        var userId = [[${session.user.id}]];
        $.ajax({
            type: "post",
            url: "/user/verifyLoginPwd",
            dataType: 'json',
            data: {
                "loginpwd": $("#oldPwd").val(),
                "id": userId
            },
            success: function (data) {
                if (data.code == 200) {
                    $("#pwdMsg").attr("code", "500");
                    // $.toast("旧密码错误", "text");
                }
                if (data.code == 500) {
                    $("#pwdMsg").attr("code", "200");
                }
            }
        });
    });

</script>

</body>
</html>
